<template>
  <div>
    <el-select v-model="name" size="mini" style="width:100%" clearable
               @clear="clear" @change="dataChanged" :disabled="disabled"
               filterable :loading="loading" loading-text="加载中"
               allow-create>
      <el-option
          v-for="item in option_list"
          :key="item.id"
          :label="item.name"
          :value="item.name">
      </el-option>
    </el-select>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name:"",
      option_list:[],
      loading:false,
    }
  },
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    value: {
      type: String,
      default: function () {
        return null;
      }
    },
    disabled: {
      type: Boolean,
      default: function () {
        return false;
      }
    },
  },
  watch: {
    value: {
      async handler(newval, oldval) {
        if (newval != null && newval != "") {
          this.name = newval;
        }
      },
      immediate: true
    }
  },
  async created() {
    this.loading = true;
    this.option_list = await elm.post('/business/my/GetAllCustomer', {pageNum: 1, pageSize: 100,});
    this.loading = false;
  },
  methods: {
    dataChanged(){
      this.$emit('update:value', this.name);
      this.$emit('change', this.name);
      this.$emit('changed',this.name);
    },
    clear() {
      this.$emit('update:value', null);
    },
  }
}
</script>